'use strict';

/**
 * @param {Egg.Application} app - egg application
 */
module.exports = app => {
  const { router, controller, middleware } = app;
  const { sign, auth, rbac } = middleware;

  // 是否开启API签名验证
  const enableRSAChecker = false;

  // 注意中间件的执行顺序
  const checks = enableRSAChecker ? [sign(), auth(), rbac()] : [auth()];

  // 上传
  router.post('/api/upload/file', controller.upload.file);

  // 登录
  if (enableRSAChecker) {
    router.post('/api/member/login', sign(), controller.member.login);
  } else {
    router.post('/api/member/login', controller.member.login);
  }

  // banner
  router.get('/api/banner/list', controller.banner.allList);
  router.resources('banner', '/api/banner', controller.banner);
  // 商品分类
  router.get('/api/category/list', controller.category.allList);
  router.resources('category', '/api/category', controller.category);
  // 商品
  router.get('/api/goods/list', controller.goods.allList);
  router.resources('goods', '/api/goods', controller.goods);
  // 商品订单
  router.get('/api/orderGoods/list', controller.orderGoods.allList);
  router.resources('orderGoods', '/api/orderGoods', controller.orderGoods);
  router.resources('orderGoodsDetail', '/api/orderGoodsDetail', controller.orderGoodsDetail);
  router.resources('express', '/api/express', controller.express);
  // 礼品分类
  router.get('/api/categoryGift/list', controller.categoryGift.allList);
  router.resources('categoryGift', '/api/categoryGift', controller.categoryGift);
  // 礼品
  router.get('/api/gift/list', controller.gift.allList);
  router.resources('gift', '/api/gift', controller.gift);
  // 礼品
  router.get('/api/giftSend/list', controller.giftSend.allList);
  router.resources('giftSend', '/api/giftSend', controller.giftSend);

  router.get('/api/giftSendItem/list', controller.giftSendItem.allList);
  router.get('/api/giftSendItem/publishList', controller.giftSendItem.publishList);
  router.post('/api/giftSendItem/get', controller.giftSendItem.get);
  router.resources('giftSendItem', '/api/giftSendItem', controller.giftSendItem);
  // 会员
  router.get('/api/member/list', controller.member.allList);
  router.resources('member', '/api/member', controller.member);
  // 地址
  router.get('/api/address/list', controller.address.allList);
  router.post('/api/address/updateStatus', controller.address.updateStatus);
  router.resources('address', '/api/address', controller.address);
};
